package com.chenfan.process.dto;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Objects;

/**
 * @author K
 * @date 2021/1/25
 */
@Data
@Builder
public class ApprovalDTO {

    @ApiModelProperty(value = "项目名称", hidden = true)
    private String projectName;

    @ApiModelProperty(value = "发起者ID", example = "1", hidden = true)
    private Long useId;

    @ApiModelProperty(value = "发起者名称", example = "大明", hidden = true)
    private String userName;

    @ApiModelProperty(value = "指定的用户ID", example = "1", hidden = true)
    private Long nextUserId;

    @ApiModelProperty(value = "指定的用户名称", example = "大明", hidden = true)
    private String nextUserName;

    @ApiModelProperty(value = "业务参数", example = "{\"id\": \"1\"}")
    private Params param;

    @ApiModelProperty("业务id")
    private Long businessId;

    @ApiModelProperty("业务code")
    private String businessCode;

    @ApiModelProperty(value = "待办参数")
    private String businessParam;

    @ApiModelProperty(value = "检查参数, 发起时有条件分支需要传递", example = "{\"brandId\": \"1\"}")
    private CheckField checkField;

    private boolean forced;

    public CheckField getCheckField() {
        return Objects.isNull(checkField) ? CheckField.builder().build() : checkField;
    }

    public boolean autoNotifyCheck() {
        return Objects.nonNull(businessId) && !(businessCode == null || "".equals(businessCode));
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Params {
        @ApiModelProperty("审批标识")
        private boolean approvalFlag;

        @ApiModelProperty("参数, 用于回调")
        private String parameter;

        @ApiModelProperty("检查参数")
        private String checkParam;

        @ApiModelProperty("审批意见")
        private String remark;
    }

    @Data
    @Builder
    public static class CheckField {
        private String checkFields;
    }
}
